package com.fks.fks_service.mapper;

import com.fks.fks_service.pojo.ShopDB;
import com.fks.fks_service.utils.ProxyCommissionRecordSql;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface ShopMapper {

    @Update("update fks_shop set isDelete='0' where id=#{id}")
    int restoreShop(int id);

    @Update("update fks_shop set updateTime=#{nowTime} where id=#{id}")
    int updateShopTime(String nowTime,int id);

    @Select("select * from fks_shop where isDelete='0' and status='1' order by" +
            " seeNum desc limit #{page},#{pageSize}")
    List<ShopDB> getShopList(int page, int pageSize);

    @Select("select count(*) from fks_shop where isDelete='0' and status='1' order by" +
            " seeNum desc ")
    int getShopListNumber();

    @Select("select * from fks_shop where id=#{id} and isDelete=0 and status=1")
    ShopDB getShop(int id);

    @Update("update fks_shop set seeNum=#{seeNum} where id=#{id}")
    int addSeeNum(int id, int seeNum);

    @Select("select * from fks_shop where (introduction like '%${information}%' or title like '%${information}%') and isDelete=0 and status=1 " +
            " limit #{page},#{pageSize}")
    List<ShopDB> selectShopByTitleOrIntroduction(String information,int page, int pageSize);

    @Select("select * from fks_shop where (introduction like '%${information}%' or title like '%${information}%')  " +
            "and isDelete=0 and status=1 limit #{page},#{pageSize}")
    List<ShopDB> selectMerchantShopByTitleOrIntroduction(String information,int page, int pageSize);

    @Select("select * from fks_shop where categoryId=#{categoryId} and isDelete='0' and status=1 ")
    List<ShopDB> getShopByCategory(int categoryId);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectListNumber")
    int getAdminShopListNumber(@Param("id") String id, @Param("title") String title, @Param("categoryName") String categoryName
            , @Param("status") String status, @Param("isDelete") String isDelete);

    @SelectProvider(type = ProxyCommissionRecordSql.class, method = "selectList")
    List<ShopDB> getAdminShopList(@Param("id") String id, @Param("title") String title, @Param("categoryName") String categoryName
            , @Param("page") String page, @Param("pageSize") String pageSize
            , @Param("status") String status, @Param("isDelete") String isDelete);

    @Update("update  fks_shop set isDelete='1',status=2 where categoryId=#{id}")
    int deleteByCategoryId(int id);

    @Update("update fks_shop set isDelete='1',status=2 where id=#{id}")
    int deleteShop(int id);

    @Insert("insert into fks_shop (title,introduction,status,seeNum,createTime,isDelete,categoryId" +
            ",createAdminId,detailImages,bannerImages,price" +
            ",salesVolume,categoryName1,categoryName2,categoryName3)" +
            "values(#{title},#{introduction},#{status},#{seeNum},#{createTime},#{isDelete}" +
            ",#{categoryId},#{createAdminId},#{detailImages},#{bannerImages},#{price}" +
            ",#{salesVolume},#{categoryName1},#{categoryName2},#{categoryName3}" +
            ")")
    int addShop(ShopDB shopDB);

    @Select("select id from fks_shop where createTime=#{createTime} and createAdminId=#{createAdminId}")
    int getShopByShop(ShopDB shopDB);

    @Update("update fks_shop set title=#{title},introduction=#{introduction}" +
            ",detailImages=#{detailImages},status=#{status},updateTime=#{updateTime}" +
            ",isDelete=#{isDelete},categoryId=#{categoryId},bannerImages=#{bannerImages}" +
            ",price=#{price},detailImages=#{detailImages}" +
            ",salesVolume=#{salesVolume} where id=#{id}")
    int updateShop(ShopDB shopDB);

    @Update("update fks_shop set status=#{status} where id=#{id}")
    int updateStatus(Integer id, Integer status);

    @Update("update fks_shop set price=#{price} where id=#{id}")
    int updatePrice(Integer id, String price);

    @Select("select * from fks_shop where  isDelete=0 and status=1 limit #{page},#{pageSize}")
    List<ShopDB> getShopListByMerchantUserId(int page,int pageSize);


    @Select("select count(*) from fks_shop where  status=#{status} and isDelete=0")
    int getShopNumberByMerchantUserIdAndStatus(String status);

    @Select("select count(*) from fks_shop where  isDelete ='1'")
    int getShopNumberDelete();

}
